<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">

    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>虹软测试数据列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="example-wrap">
                        <div class="example">
                            <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                                <button type="button" class="btn btn-outline btn-default" title="添加" data-toggle="modal"
                                        data-target="#exampleModalCenter">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>添加
                                </button>
                            </div>
                            <table class="layui-hide" id="arcsoftTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Modal -->
    <div class="modal fade" tabindex="-1" id="exampleModalCenter" role="dialog" id="arcsoft_modal"
         aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalCenterTitle">数据添加</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div id="file-pretty">
                        <div class="form-group">
                            <label class="font-noraml">虹软版本号</label>
                            <input id="version" type="text" class="form-control">
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">libarcsoft_face文件</label>
                            <input id="libarcsoft_face" type="file" class="form-control">
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">libarcsoft_face_engine文件</label>
                            <input id="libarcsoft_face_engine" type="file" multiple="multiple" class="form-control">
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">libarcsoft_face_engine_jni文件</label>
                            <input id="libarcsoft_face_engine_jni" type="file" multiple="multiple" class="form-control">
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">app_key</label>
                            <input id="app_key" type="text" class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">app_id</label>
                            <input id="app_id" type="text" class="form-control"/>
                        </div>
                        <div class="form-group">
                            <label class="font-noraml">数据样本文件 注: 必须要压缩文件 </label>
                            <input id="simple" type="file" multiple="multiple" class="form-control"/>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal" id="clock_btn">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="insert()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" tabindex="-1" id="chartModalCenter" role="dialog" id="chart_modal"
         aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">数据添加</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div id="chart" style="width: 600px;height:600px;"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.7"></script>

<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>


<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<!-- Peity -->
<script src="js/demo/bootstrap-table-demo.js"></script>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
<script>
    $(function () {
        if (Cookies.get('token') === undefined) {
            window.location.href = "http://localhost:8080/login.html";
        } else {
            setTimeout("getData()", 1);
        }
    })

    // 数据添加
    function insert() {
        var forms = new FormData();
        var configs = {
            headers: {'Content-Type': 'multipart/form-data', 'token': Cookies.get('token')}
        };
        var libarcsoft_face = $('#libarcsoft_face').prop('files');
        var libarcsoft_face_engine = $('#libarcsoft_face_engine').prop('files');
        var libarcsoft_face_engine_jni = $('#libarcsoft_face_engine_jni').prop('files');
        var simple = $('#simple').prop('files');
        var version = $('#version').val();
        var app_key = $('#app_key').val();
        var app_id = $('#app_id').val();

        forms.append('libarcsoftFace', libarcsoft_face[0]);
        forms.append('libarcsoftFaceEngine', libarcsoft_face_engine[0]);
        forms.append('libarcsoftFaceEngineJni', libarcsoft_face_engine_jni[0]);
        forms.append('simple', simple[0]);
        forms.append('version', version);
        forms.append('appKey', app_key);
        forms.append('appId', app_id);

        axios.post('/arcsoft/insert', forms, configs).then(res => {
            if (res.data.code === 0) {
                alert("添加成功");
                // 关闭模态框
                setTimeout(function () {
                    $("#clock_btn").click()
                })
                setTimeout(function () {
                    // 刷新数据
                    getData();
                })
            } else {
                var {message, data, code} = res.data
                alert(message)
            }
        })

    }

    function getData() {
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#arcsoftTable'
                , headers: {token: Cookies.get('token')}
                , url: '/arcsoft/list'
                , cellMinWidth: 80 // 全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    {field: 'id', title: 'ID'}
                    , {field: 'version', title: '虹软版本号'}
                    , {field: 'appKey', title: 'AppKey'}
                    , {field: 'appId', title: 'AppId'}
                    , {field: 'createDate', title: '创建时间'}
                    , {field: 'updateDate', title: '更新时间'}
                    , {
                        field: 'action', title: '操作', align: 'center',
                        templet: function (data) {
                            var editBtn = '<a class="layui-btn layui-btn-xs" lay-event="del" data-toggle="modal" data-target="#chartModalCenter" onclick="task(\'' + data.id + '\')"><i class="fa fa-edit"></i>测试</a>';
                            var addBtn = '<a class="layui-btn layui-btn-normal layui-btn-xs" onclick=del(\'' + data.id + '\') lay-event="editor"><i class="fa fa-trash-o"></i>删除</a>';
                            return editBtn + addBtn;
                        }
                    }
                ]],
                limit: 10,
                page: true,
                totalRow: false,  //开启合计行
                parseData: function (res) { //res 即为原始返回的数据
                    if (res.code === 403) {
                        window.location.href = "http://localhost:8080/login.html";
                    }
                    if (res.code !== 0) {
                        if (res.code)
                            return {
                                "code": res.code, //解析接口状态
                                "message": res.message, //解析提示文本
                                "count": 0, //解析数据长度
                                "data": [] //解析数据列表
                            };
                    }
                    return {
                        "code": res.code, //解析接口状态
                        "message": res.message, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                }
            });
        });
    }

    function task(id) {
        var configs = {
            headers: {'token': Cookies.get('token')}
        };
        axios.post('/arcsoft/task?id=' + id, {}, configs).then(res => {
            var data = res.data
            if (data.code === 0) {
                setTimeout(function () {
                    let far_data_value = data.data['far'][0];
                    let frr_data_value = data.data['frr'][0];
                    var chartDom = document.getElementById('chart');
                    // 基于准备好的dom，初始化echarts实例
                    // 指定图表的配置项和数据
                    var myChart = echarts.init(chartDom);
                    var option;
                    option = {
                        xAxis: {
                            type: 'category',
                            data: [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5]
                        },
                        yAxis: {
                            type: 'value'
                        },
                        legend: {
                            data: ['frr', 'far']
                        },
                        series: [
                            {
                                name: 'frr',
                                stack: 'Total',
                                data: frr_data_value,
                                type: 'line'
                            },
                            {
                                name: 'far',
                                stack: 'Total',
                                data: far_data_value,
                                type: 'line'
                            }
                        ]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    option && myChart.setOption(option);

                })
            } else {
                alert(res.data.message)
            }
        })
    }

    function del(id) {
        var configs = {
            headers: {'token': Cookies.get('token')}
        };
        axios.post('/arcsoft/delete?id=' + id, {}, configs).then(res => {
            if (res.data.code === 0) {
                alert("操作成功")
                setTimeout(function () {
                    // 刷新数据
                    getData();
                })
            } else {
                alert(res.data.message)
            }
        })
    }

</script>
</body>

</html>
